<%@ page import="java.util.*,com.running.util.StringUtils,com.running.util.FileOperator" contentType="text/html; charset=utf-8"%><%
Map mms = (Map)request.getAttribute("mms");
List<Map> smilContents = (List<Map>)request.getAttribute("smilContents");
List<Map> mmsContents = (List<Map>)request.getAttribute("mmsContents");
String rootDir = config.getServletContext().getRealPath("/").replaceAll("\\\\","/");	//根目录
if (rootDir.endsWith("/")) {
	rootDir = rootDir.substring(0,rootDir.length()-1);
}
%>

<html>
<head>
<script language="javascript">
var returnUrl;
var tmpImgFileDir = new Array();
var tmpImgFileName = new Array();
var tmpImgFileSize = new Array();
//var tmpVoiFileDir = new Array();
//var tmpVoiFileName = new Array();
//var tmpVoiFileSize = new Array();
var tmpMmsText = new Array();
var tmpFrameTime = new Array();
function PopDialog(fileDirObj,fileNameObj,fileSizeObj,disObj){
	var url ="file.htm";
	returnUrl = showModalDialog(url, window, 'dialogWidth:400px;dialogHeight:220px;help:no;scroll:no;status:no');
	if(returnUrl){
		fileDirObj.value = returnUrl[0]
		fileNameObj.value = returnUrl[1];
		fileSizeObj.value = returnUrl[2];
		if(disObj){
			//显示在页面上的img路径,也就是img的src
			disObj.src = returnUrl[0]+"/"+returnUrl[1];
		}
	}
}

window.onload = function Init(){
	var objMmsContainer = document.getElementById('oFrameSpan');
	oForm.frameCount.value="<%=smilContents.size()%>";
	loadMmsContent();
	setFrame(oForm.frameCount.value);
}

function setFrame(iFrameCount){
	var objMmsContainer = document.getElementById('oFrameSpan');
	if (objMmsContainer) {
		if (objMmsContainer.children)
			oldFrameCount = objMmsContainer.children.length;
		for (var i=1;i<=oldFrameCount;i++) {
			tmpImgFileDir[i-1] = document.all("imgFileDir"+i).value;
			tmpImgFileName[i-1] = document.all("imgFileName"+i).value;
			tmpImgFileSize[i-1] = document.all("imgFileSize"+i).value;
			tmpMmsText[i-1] = document.all("mmsText"+i).value;
			tmpFrameTime[i-1] = document.all("frameTime"+i).value;
		}
	}
	var sFrame = "";
	for(var i=1;i<=parseInt(iFrameCount);i++){
		if (tmpImgFileDir.length>=i) {
			sFrame += buildMmsFrame(i,tmpImgFileDir[i-1],tmpImgFileName[i-1],tmpImgFileSize[i-1],tmpMmsText[i-1],tmpFrameTime[i-1]);
		} else {//一切新增
			sFrame += buildMmsFrame(i,"","","","","");
		}
	}
	document.all("oFrameSpan").innerHTML = sFrame;
}

function loadMmsContent() {
<%
int i = 0;
for(Map smilContent:smilContents){
	out.println("tmpImgFileDir["+i+"]=''");
	out.println("tmpImgFileName["+i+"]=''");
	out.println("tmpImgFileSize["+i+"]=''");
	out.println("tmpMmsText["+i+"]=''");
	out.println("tmpFrameTime["+i+"]='10'");
	for (Map mmsContent : mmsContents) {
		if (StringUtils.varFormat(String.valueOf(smilContent.get("imgFileName"))).equals(mmsContent.get("file_name"))) {
			out.println("tmpImgFileDir["+i+"]='"+mmsContent.get("file_dir")+"'");
			out.println("tmpImgFileName["+i+"]='"+mmsContent.get("file_name")+"'");
			out.println("tmpImgFileSize["+i+"]='"+mmsContent.get("file_size")+"'");
		}
		if (StringUtils.varFormat(String.valueOf(smilContent.get("txtFileName"))).equals(mmsContent.get("file_name"))) {
			if (FileOperator.exists(rootDir + "/" + mmsContent.get("file_dir") + "/" + mmsContent.get("file_name"))) {
				out.println("tmpMmsText["+i+"]='"+FileOperator.read(rootDir + "/" + mmsContent.get("file_dir") + "/" + mmsContent.get("file_name")).replace("\r\n","\\r\\n").replace("'","\\'")+"'");
			}
		}
	}
	if (!StringUtils.varFormat(String.valueOf(smilContent.get("frameTime"))).equals("")) {
		out.println("tmpFrameTime["+i+"]='"+StringUtils.varFormat(String.valueOf(smilContent.get("frameTime")))+"'");
	}
	i++;
}	
%>
}
</script>
  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
</head>
<body>
<form name="oForm" onsubmit="return ValidateForm(this)" method="POST" action="mmsConfig.do?method=saveEdit">
<table id="FormTable">
<caption>修改彩信内容</caption>
<tr>
	<td colspan="2"><font class="FieldItem">彩信标题<font class="NotNull">(*必填项)</font></font><br/>
		<input type="text" name="subject" _dataType="string" value="<%=mms.get("mms_subject")%>" _cnName="彩信标题" _dataEmpty = "false" _dataLength="50"/>
	</td>
</tr>
<tr><td colspan="2">
	<font class="FieldItem">选择帧数</font><br/>
	<select name="frameCount" onchange="setFrame(this.value);">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
		<option value="6">6</option>
		<option value="7">7</option>
	</select>
</td></tr>
<tr><td>
	<fieldset>
		<legend>编辑彩信</legend>
		<span id="oFrameSpan">
		</span>
	</fieldset>		
</td></tr>
<tr><td>

<label for="oDefaultIncomingcallMms" style="cursor:hand;">
<input type="checkbox" name="incomingCallState" value="Y" class="DefaultCheckBox" id="oDefaultIncomingcallMms" <%="Y".equals(mms.get("incoming_call_state"))?" checked":""%>/>
<font style="vertical-align:middle">来电发送</font></label>
<label for="oDefaultOutcomingcallMms" style="cursor:hand;">
<input type="checkbox" name="outcomingCallState" value="Y" class="DefaultCheckBox" id="oDefaultOutcomingcallMms" <%="Y".equals(mms.get("outcoming_call_state"))?" checked":""%>/>
<font style="vertical-align:middle">去电发送</font></label>
</td></tr>
<tr><td colspan="2"><HR/></td></tr>
<tr><td><input type="submit" name="btnSubmit" value=" 保 存 " class="DefaultButton"/>&nbsp;<input type="button" name="btnCancel" value=" 取 消 " class="DefaultBtnCancel"/></td></tr>
</table>
<input type="hidden" name="mmsSid" value="<%=mms.get("mms_sid")%>"/>
<input type="hidden" name="company" value="<%=request.getParameter("company")%>"/>
</form>
</body>
</html>